
package com.netease.xone.widget.listview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.handmark.pulltorefresh.library.PullToRefreshExpandableListView;
import com.netease.xone.R;

public class LoadingExpandableListView extends PullToRefreshExpandableListView {

    private Context mContext;
    private TextView mLoadingErrorText;
    private TextView mNoContentText;

    public LoadingExpandableListView(Context context) {
        this(context, null);
    }

    public LoadingExpandableListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
    }

    @Override
    protected View getLoadingView() {
        View v = View.inflate(mContext, R.layout.view_loading, null);
        TextView text = (TextView)v.findViewById(R.id.loading_text);
        text.setText(R.string.loading_default);
        return v;
    }

    @Override
    protected View getLoadingErrorView() {
        View v = View.inflate(mContext, R.layout.view_load_complete, null);
        mLoadingErrorText = (TextView)v.findViewById(R.id.loading_text);
        mLoadingErrorText.setText(R.string.error_loading_default);
        return v;
    }

    @Override
    protected View getLoadingFooterView() {
        View v = View.inflate(mContext, R.layout.view_loading, null);
        TextView text = (TextView)v.findViewById(R.id.loading_text);
        text.setText(R.string.loading_more_default);
        ImageView loadingImage = (ImageView)v.findViewById(R.id.loading_image);
        loadingImage.setVisibility(View.GONE);
        return v;
    }

    @Override
    protected View getNoContentView() {
        View v = View.inflate(mContext, R.layout.view_load_complete, null);
        mNoContentText = (TextView)v.findViewById(R.id.loading_text);
        mNoContentText.setText(R.string.success_no_content_default);
        return v;
    }

    @Override
    protected View getNoNetworkView() {
        View v = View.inflate(mContext, R.layout.view_load_complete, null);
        TextView noNetworkText = (TextView)v.findViewById(R.id.loading_text);
        noNetworkText.setText(R.string.error_no_network);
        TextView retry = (TextView)v.findViewById(R.id.loading_text2);
        retry.setVisibility(View.VISIBLE);
        retry.setText(R.string.error_retry);
        retry.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                load();
            }
        });
        return v;
    }

    public void onNoContent(String tipString) {
        mNoContentText.setText(tipString);
        super.onNoContent();
    }

    public void onLoadingError(String errorString) {
        mLoadingErrorText.setText(errorString);
        super.onLoadingError();
    }


}
